home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS Toolkit
/
BBS Toolkit.iso
/
maximus
/
mul100.zip
/
MAKUSER.SCR
< prev
next >
Wrap
Text File
|
1993-02-01
|
13KB
|
348 lines
// MAKUSER.SCR -- Add a defined record to Maximus Base -- Version 1.00
//
// Script program for MUL - the Maximus User Language
// MUL is (C) Copyright 1990-93 by CodeLand Australia
// Originally written for David Keating of 1:249/201, MAKUSER appends
// or updates a record in the Maximus user base. The record information
// used for the new or updated record is obtained from an external
// text file, presumably created by another utility. See the example
// MAKUSER.DAT file provided with this script. Following is David's
// input file specification, as implimented in this script with the
// read_data () function.
// INPUT TEXT FILE KEYWORDS:
//
// NAME (their name)
// PASSWORD (xxxxxxx)
// CITY (city,prov)
// PHONE (xxx-xxx-xxxx)
// ALIAS (whatever)
// ACCESS (Limited, etc.)
// KEYS (1-8,A-X)
// EXPIRY (date, time)
// EXPIRYDATE (mm/dd/yy)
// EXPIRYACTION (demote,hangup)
// DEMOTE (level to demote to)
// MAKUSER supports one optional command line parameter MODIFY, which
// forces the record modification mode, rather than the default
// append mode. MAKUSER return a status of zero on success, and the
// following error levels when trouble arises. Note that MUL will return
// to DOS the exact value the script returns. Thus it's best as below,
// to avoid the first 16 values, which are reserved for errors internal
// to MUL itself. See the documentation for further details.
// MAKUSER return status: 0 - Success
// 17 - Input file not found
// 18 - User file not found
// 19 - User file append failed
// 20 - User file write failed
// 21 - Modification record NOT found
// 22 - Modification password mismatch
// 23 - Input name or password not found
// 24 - Append record already exists
char *ufile = "USER.BBS"; // Path & name of Maximus user file
char *ifile = "MAKUSER.DAT"; // Path & name of input file
char *banner = "MAKUSER v1.00"; // Script banner
char *desc = "Append a new user record"; // Description
// Input fields
char usrname[36]; // (their name)
char usrpwd[16]; // (xxxxxxx)
char usrcity[36]; // (city,prov)
char usrphone[15]; // (xxx-xxx-xxxx)
char usralias[21]; // (whatever)
int usrpriv; // (Limited, etc.)
long usrkeys; // (1-8,A-X)
int usrexpiry; // (date, time)
int usrexpiryaction; // (demote,hangup)
int usrxpdate; // (mm/dd/yy)
int usrxppriv; // (level to demote to)
int modifyflag=0; // Modify existing record flag
int status=0; // Script return status
long fp; // Text record input file handle
main (int argc, char *arg1) // Main program
{
printf ("\n%s - %s\n\n",banner,desc); // Announce
getcmdline (argc,arg1); // Get the command line
if (process_input ()) update_base (); // Process data and append record
saybibi ();
exit (status); // Return status
}
process_input () // Process the input data file
{
int count;
if (!fp=fopen (ifile,"rt")) {
printf ("ERROR opening input file %s\n",ifile);
status=17; return 0;
}
// Notify
printf ("Reading input file \"%s\" ",ifile);
count=read_data (); // Parse the input file
fclose (fp); // Close the input file
putch ('\n'); // Notify cleanup
if (count<2) { // Name & Password are required
status=23;
return 0;
}
// Notify
printf ("Input record: %s from %s\n",usrname,usrcity);
return count;
}
update_base () // Add the new record
{
int found;
if (!BaseOpen (ufile)) {
printf ("\nERROR opening user file %s\n",ufile);
status=18; return 0;
}
// Notify
printf ("Updating user file \"%s\" ",ufile);
found=find_record (); // Check for existance
if (modifyflag) {
// Modify existing record
if (found) { // The record must exist
if (!stricmp (usrpwd,USRpwd)) { // Passwords must match
// Transfer new data
if (usrcity[0]) strcpy (USRcity,usrcity);
if (usrphone[0]) strcpy (USRphone,usrphone);
if (usralias[0]) strcpy (USRalias,usralias);
if (usrpriv) USRpriv=usrpriv;
if (usrkeys) USRkeys=usrkeys;
if (usrexpiry) USRxpflag=Or (usrexpiry,usrexpiryaction);
if (usrxppriv) USRxppriv=usrxppriv;
if (usrxpdate) USRxpdate=usrxpdate;
if (!BaseWrite (found)) {
status=20;
printf ("\nERROR base write failed");
}
}
else {
status=22;
printf ("\nERROR Modification password mismatch");
}
}
else {
status=21;
printf ("\nERROR Modification record NOT found");
}
}
else {
// Append new record
if (found) { // The record must NOT exist
status=24;
printf ("\nERROR Append record already exists");
}
else {
BaseClear (); // Clear record buffer
strcpy (USRname,usrname); // Transfer data to record buffer
strcpy (USRpwd,usrpwd);
strcpy (USRcity,usrcity);
strcpy (USRphone,usrphone);
strcpy (USRalias,usralias);
USRpriv=usrpriv;
USRkeys=usrkeys;
USRxpflag=Or (usrexpiry,usrexpiryaction);
USRxppriv=usrxppriv;
USRxpdate=usrxpdate;
if (!BaseAppend ()) {
status=19;
printf ("\nERROR base append failed");
}
}
}
BaseClose (); // Close the user base
putch ('\n'); // Notify cleanup
}
find_record () // Check for record existance
{
int rec;
for (rec=1;rec<=BaseCount ();++rec) {
if (!BaseRead (rec)) break;
if (!stricmp (usrname,USRname)) { // If names match
return rec; // Return success
}
}
return 0;
}
read_data () // Parse the input file
{
int verbs=0; // Required verbs processed count
char *p, *q, line[256];
while (fgets (line,256,fp)) { // Read a line from text file
p=line; while (isspace (*p)) p++; // Skip leading white space
strip_nl (p); // Remove trailing NL & whitespace
if (strlen (p) && p[0]!=';') { // If a valid line
// printf("\"%s\"\n",p); // Debug
q=p;
while(*q&&!isspace (*q)) q++; // Find token ending
if (*q&&q!=p) { // If we have keyword plus data
*q='\0'; q++; // Point q at data
while (isspace (*q)) q++; // Skip leading white space
// Process the keyword
if (!strnicmp ("NAME",p,strlen(p))) {
++verbs;
strncpy (usrname,q,35); usrname[35]='\0';
}
else if (!strnicmp ("PASSWORD",p,strlen(p))) {
++verbs;
strncpy (usrpwd,q,15); usrpwd[15]='\0';
}
else if (!strnicmp ("CITY",p,strlen(p))) {
strncpy (usrcity,q,35); usrcity[35]='\0';
}
else if (!strnicmp ("PHONE",p,strlen(p))) {
strncpy (usrphone,q,15); usrphone[15]='\0';
}
else if (!strnicmp ("ALIAS",p,strlen(p))) {
strncpy (usralias,q,20); usralias[20]='\0';
}
else if (!strnicmp ("ACCESS",p,strlen(p))) {
usrpriv=set_access (q);
}
else if (!strnicmp ("KEYS",p,strlen(p))) {
usrkeys=set_keys (q);
}
else if (!strnicmp ("EXPIRY",p,strlen(p))) {
if (!strnicmp ("DATE",q,strlen(q))) {
usrexpiry=XP_DATE;
}
else if (!strnicmp ("TIME",q,strlen(q))) {
usrexpiry=XP_TIME;
}
else printf ("\nERROR: Unknown expiry type - \"%s\"\n",q);
}
else if (!strnicmp ("EXPIRYDATE",p,strlen(p))) {
usrxpdate=StrToDate (q);
}
else if (!strnicmp ("EXPIRYACTION",p,strlen(p))) {
if (!strnicmp ("DEMOTE",q,strlen(q))) {
usrexpiryaction=XP_DEMOTE;
}
else if (!strnicmp ("HANGUP",q,strlen(q))) {
usrexpiryaction=XP_HANGUP;
}
else printf ("\nERROR: Unknown expiry action - \"%s\"\n",q);
}
else if (!strnicmp ("DEMOTE",p,strlen(p))) {
usrxppriv=set_access (q);
}
else printf ("\nERROR: Unrecognised keyword - \"%s\"\n",p);
}
else { // Check for non-data keywords
if (!strnicmp ("MODIFY",p,strlen(p))) {
++modifyflag;
}
else printf ("ERROR: Unrecognised keyword - \"%s\"\n",p);
}
}
}
return verbs;
}
set_access (char *str) // Return binary priv from str priv
{
if (!strnicmp ("TWIT",str,4)) return TWIT;
if (!strnicmp ("DISGRACE",str,8)) return DISGRACE;
if (!strnicmp ("LIMITED",str,7)) return LIMITED;
if (!strnicmp ("NORMAL",str,6)) return NORMAL;
if (!strnicmp ("WORTHY",str,6)) return WORTHY;
if (!strnicmp ("PRIVIL",str,6)) return PRIVIL;
if (!strnicmp ("FAVORED",str,7)) return FAVORED;
if (!strnicmp ("EXTRA",str,5)) return EXTRA;
if (!strnicmp ("CLERK",str,5)) return CLERK;
if (!strnicmp ("ASSTSYSOP",str,9)) return ASSTSYSOP;
if (!strnicmp ("SYSOP",str,5)) return SYSOP;
if (!strnicmp ("HIDDEN",str,6)) return HIDDEN;
return DISGRACE;
}
set_keys (char *str) // Return binary keys from key str
{
long keybit;
char *p=str;
USRkeys=0;
while (*p) {
if (isdigit (*p)) {
// Get key bit
keybit = ShiftLeft (1,*p-49);
BaseKeyOn (keybit); // Turn key on
}
else if (isalpha (*p)) {
// Get key bit
keybit = ShiftLeft (1,toupper (*p)-57);
BaseKeyOn (keybit); // Turn key on
}
p++;
}
return USRkeys;
}
strip_nl (char *str) // Remove trailing NL & whitespace
{
char *p;
p=str+strlen(str)-1; // Point at last character
while (p!=str) {
if(!isspace (*p) || *p!='\n') break;
p--;
}
if(isspace (*p) || *p=='\n') *p='\0'; // Terminate string
else p[1]='\0';
}
getcmdline (int argc, char *arg1) // Get the command line
{
// Check for the MODIFY command line option
if (argc) if (!stricmp (arg1,"MODIFY")) ++modifyflag;
}
// Byebye
saybibi ()
{
puts ("\nMakUser done!\n");
}
// End of script